﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;



namespace DotNetNuke.Tests.UI.WatiN.AdministratorTests
{
    [TestFixture]


    public class AdminSkinTests : ATBase
    {
        public bool SkinInstalled = false;
        public bool SkinorContainerApplied = false;

        #region Test Setup and TearDown


        [SetUp]
        public void SetUp()
        {

            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            if (SkinorContainerApplied || SkinInstalled)
            {
                WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
                LoginPage loginPage = new LoginPage(homePage);
                ieInstance.GoTo(SiteURL + "/Home.aspx");
                if (!homePage.RegisterLink.Text.Contains(TestUsers.Host.DisplayName))
                {
                    if (!homePage.RegisterLink.Text.Equals("Register"))
                    {
                        loginPage.LogoffUser();

                    }
                    loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
                }
                if (SkinorContainerApplied)
                {
                    ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
                    AdminSkinPage skinPage = new AdminSkinPage(homePage);
                    skinPage.SkinSelectList.Select("<Not Specified>");
                    skinPage.ContainerSelectList.Select("MinimalExtropy");
                    skinPage.FirstApplyButton.Click();
                    skinPage.SkinSelectList.Select("MinimalExtropy");
                    skinPage.FirstApplyButton.Click();
                    ieInstance.GoTo(SiteURL + "/Home.aspx");
                    SkinorContainerApplied = false;
                }
                if (SkinInstalled)
                {
                    ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
                    ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
                    extensionsPage.ExtensionPackageSelectList.Select("Skin");
                    System.Threading.Thread.Sleep(500);
                    extensionsPage.GetExtensionUninstallButton(SkinName).Click();
                    System.Threading.Thread.Sleep(2000);
                    extensionsPage.DeleteExtensionFilesCheckbox.Checked = true;
                    ConfirmDialogHandler dialog = new ConfirmDialogHandler();
                    using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
                    {
                        extensionsPage.UninstallPackageLink.ClickNoWait();
                        dialog.WaitUntilExists();
                        dialog.OKButton.Click();
                    }
                    ieInstance.WaitForComplete();
                    //Uninstall the Container
                    ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
                    extensionsPage.ExtensionPackageSelectList.Select("Container");
                    System.Threading.Thread.Sleep(500);
                    extensionsPage.GetExtensionUninstallButton(SkinName).Click();
                    System.Threading.Thread.Sleep(2000);
                    extensionsPage.DeleteExtensionFilesCheckbox.Checked = true;
                    dialog = new ConfirmDialogHandler();
                    using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
                    {
                        extensionsPage.UninstallPackageLink.ClickNoWait();
                        dialog.WaitUntilExists();
                        dialog.OKButton.Click();
                    }
                    ieInstance.WaitForComplete();
                    string skinsPath = Path.Combine(PhysicalPath, "Portals", "0");
                    if (Directory.Exists(Path.Combine(skinsPath, "Skins", SkinName)))
                    {
                        Directory.Delete(Path.Combine(skinsPath, "Skins", SkinName), true);
                    }
                    if (Directory.Exists(Path.Combine(skinsPath, "Containers", SkinName)))
                    {
                        Directory.Delete(Path.Combine(skinsPath, "Containers", SkinName), true);
                    }
                    SkinInstalled = false;
                }
            }
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Preview_Skin()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.SkinSelectList.Select(SkinName);
            skinPage.FirstPreviewButton.Click();

            //Assert
            System.Threading.Thread.Sleep(3000);
            Regex regex = new Regex(SiteURL.ToLower() + @"/Home/tabid/\d\d/Default\.aspx\?SkinSrc=\[\w\]...skins...maple.*");
            IE previewWindow = IE.AttachTo<IE>(Find.ByUrl(regex));
            System.Threading.Thread.Sleep(2000);
            Regex stylesheetRegex = new Regex(@".*_Skins_" + SkinName + "_", RegexOptions.IgnoreCase);
            ElementContainer<Element> header = (ElementContainer<Element>)previewWindow.Element(Find.ById("Head"));
            Element stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String minimalExtropyString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropyString = "Skins_MinimalExtropy_";
            }
            else
            {
                minimalExtropyString = "Skins_MinimalExtropyPro_";
            }

            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            previewWindow.Close();
            
        }

        [Test]
        public void Preview_Container()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.ContainerSelectList.Select(SkinName);
            skinPage.FirstPreviewButton.Click();

            //Assert
            System.Threading.Thread.Sleep(3000);
            Regex regex = new Regex(SiteURL.ToLower() + @"/Home/tabid/\d\d/Default\.aspx\?ContainerSrc=\[\w\]...containers...maple.*");
            IE previewWindow = IE.AttachTo<IE>(Find.ByUrl(regex));
            System.Threading.Thread.Sleep(2000);
            Regex stylesheetRegex = new Regex(@".*_Containers_" + SkinName + "_", RegexOptions.IgnoreCase);
            ElementContainer<Element> header = (ElementContainer<Element>)previewWindow.Element(Find.ById("Head"));
            Element stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String minimalExtropyString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropyString = "Containers_MinimalExtropy_";
            }
            else
            {
                minimalExtropyString = "Containers_MinimalExtropyPro_";
            }

            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            previewWindow.Close();

        }

        [Test]
        public void Apply_Skin_To_Portal()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            ElementContainer<Element>header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String minimalExtropyString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropyString = "Skins_MinimalExtropy_";
            }
            else
            {
                minimalExtropyString = "Skins_MinimalExtropyPro_";
            }

            Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.SkinSelectList.Select(SkinName);
            skinPage.AdminCheckBox.Checked = false;
            skinPage.FirstApplyButton.Click();

            //Assert
            Regex stylesheetRegex = new Regex(@".*_Skins_" + SkinName + "_", RegexOptions.IgnoreCase);
            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            if (homePage.ControlPanelElement.Id.CompareTo("dnn_RibbonBar.ascx_RB") == 0)
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.EditCurrentPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.PageSettingsLink.Click();
            }
            System.Threading.Thread.Sleep(1000);
            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            SkinorContainerApplied = true;
        }


        [Test]
        public void Apply_Skin_To_Admin_Pages()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            
            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.SkinSelectList.Select(SkinName);
            skinPage.PortalCheckBox.Checked = false;
            skinPage.FirstApplyButton.Click();

            //Assert
            ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String minimalExtropyString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropyString = "Skins_MinimalExtropy_";
            }
            else
            {
                minimalExtropyString = "Skins_MinimalExtropyPro_";
            }

            Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            if (homePage.ControlPanelElement.Id.CompareTo("dnn_RibbonBar.ascx_RB") == 0)
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.EditCurrentPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.PageSettingsLink.Click();
            }
            System.Threading.Thread.Sleep(1000);
            Regex stylesheetRegex = new Regex(@".*_Skins_" + SkinName + "_", RegexOptions.IgnoreCase);
            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            SkinorContainerApplied = true;
        }


        [Test]
        public void Apply_Container_To_Admin_Pages()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.ContainerSelectList.Select(SkinName);
            skinPage.PortalCheckBox.Checked = false;
            skinPage.FirstApplyButton.Click();

            //Assert
            ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String minimalExtropyString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropyString = "Containers_MinimalExtropy_";
            }
            else
            {
                minimalExtropyString = "Containers_MinimalExtropyPro_";
            }

            Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            if (homePage.ControlPanelElement.Id.CompareTo("dnn_RibbonBar.ascx_RB") == 0)
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.EditCurrentPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.PageSettingsLink.Click();
            }
            System.Threading.Thread.Sleep(1000);
            Regex stylesheetRegex = new Regex(@".*_Containers_" + SkinName + "_", RegexOptions.IgnoreCase);
            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            SkinorContainerApplied = true;
        }

        [Test]
        public void Apply_Container_To_Portal_Pages()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.ContainerSelectList.Select(SkinName);
            skinPage.AdminCheckBox.Checked = false;
            skinPage.FirstApplyButton.Click();

            //Assert
            Regex stylesheetRegex = new Regex(@".*_Containers_" + SkinName + "_", RegexOptions.IgnoreCase);
            ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            Element stylesheet = header.Elements.Filter(Find.ById(stylesheetRegex))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);


            
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            if (homePage.ControlPanelElement.Id.CompareTo("dnn_RibbonBar.ascx_RB") == 0)
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.EditCurrentPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.PageSettingsLink.Click();
            }
            System.Threading.Thread.Sleep(1000);
            header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            String minimalExtropyString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropyString = "Containers_MinimalExtropy_";
            }
            else
            {
                minimalExtropyString = "Containers_MinimalExtropyPro_";
            }

            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            SkinorContainerApplied = true;
        }

        [Test]
        public void Display_Host_Skins_Containers_Only()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.SiteSkinsCheckBox.Checked = false;
            skinPage.HostSkinsCheckBox.Checked = true;

            //Assert 
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(skinPage.ContainerSelectList.Option("MinimalExtropy").Exists);
            Assert.IsTrue(skinPage.SkinSelectList.Option("MinimalExtropy").Exists);
            Assert.IsFalse(skinPage.ContainerSelectList.Option(SkinName).Exists);
            Assert.IsFalse(skinPage.SkinSelectList.Option(SkinName).Exists);
        }

        [Test]
        public void Display_Site_Skins_Containers_Only()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.HostSkinsCheckBox.Checked = false;
            skinPage.SiteSkinsCheckBox.Checked = true;

            //Assert 
            System.Threading.Thread.Sleep(5000);
            Assert.IsFalse(skinPage.ContainerSelectList.Option("MinimalExtropy").Exists);
            Assert.IsFalse(skinPage.SkinSelectList.Option("MinimalExtropy").Exists);
            Assert.IsTrue(skinPage.ContainerSelectList.Option(SkinName).Exists);
            Assert.IsTrue(skinPage.SkinSelectList.Option(SkinName).Exists);
        }

        [Test]
        public void Display_Site_Host_Skins_Containers()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.HostSkinsCheckBox.Checked = true;
            skinPage.SiteSkinsCheckBox.Checked = true;

            //Assert 
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(skinPage.ContainerSelectList.Option("MinimalExtropy").Exists);
            Assert.IsTrue(skinPage.SkinSelectList.Option("MinimalExtropy").Exists);
            Assert.IsTrue(skinPage.ContainerSelectList.Option(SkinName).Exists);
            Assert.IsTrue(skinPage.SkinSelectList.Option(SkinName).Exists);
        }

        [Test]
        public void Delete_Skin()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.SkinSelectList.Select(SkinName);
            System.Threading.Thread.Sleep(2000);
            string skinTitle = skinPage.FirstSkinNameSpan.Text;
            int numSkins = skinPage.SkinsTable.TableCells.Count;
            skinPage.FirstDeleteSkinButton.Click();
            
            //Assert 
            Assert.IsFalse(skinPage.SkinsTable.InnerHtml.Contains(skinTitle));
            Assert.IsTrue(skinPage.SkinsTable.TableCells.Count == (numSkins - 1));
        }

        [Test]
        public void Delete_Container()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.ContainerSelectList.Select(SkinName);
            System.Threading.Thread.Sleep(2000);
            string containerTitle = skinPage.FirstContainerNameSpan.Text;
            int numContainers = skinPage.ContainersTable.TableCells.Count;
            skinPage.FirstDeleteContainerButton.Click();

            //Assert 
            Assert.IsFalse(skinPage.ContainersTable.InnerHtml.Contains(containerTitle));
            Assert.IsTrue(skinPage.ContainersTable.TableCells.Count == (numContainers - 1));
        }

        [Test]
        public void Delete_Skin_Container_Package()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Uninstall the skin
            extensionsPage.ExtensionPackageSelectList.Select("Skin");
            System.Threading.Thread.Sleep(500);
            extensionsPage.GetExtensionUninstallButton(SkinName).Click();
            System.Threading.Thread.Sleep(2000);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                extensionsPage.UninstallPackageLink.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            ieInstance.WaitForComplete();

            //Uninstall the Container
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
            extensionsPage.ExtensionPackageSelectList.Select("Container");
            System.Threading.Thread.Sleep(500);
            extensionsPage.GetExtensionUninstallButton(SkinName).Click();
            System.Threading.Thread.Sleep(2000);
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                extensionsPage.UninstallPackageLink.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            ieInstance.WaitForComplete();
            SkinInstalled = false;
            
            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.SkinSelectList.Select(SkinName);
            skinPage.DeleteSkinPackageLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            Assert.IsFalse(skinPage.SkinSelectList.Option(SkinName).Exists);
            Assert.IsFalse(skinPage.ContainerSelectList.Option(SkinName).Exists);
            Assert.IsFalse(Directory.Exists(PhysicalPath + "/Portals/_default/Containers/" + SkinName));
            Assert.IsFalse(Directory.Exists(PhysicalPath + "/Portals/_default/Skins/" + SkinName));
        }

        [Test]
        public void Delete_Container_Package()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add a Skin 
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);
            SkinInstalled = true;

            //Uninstall the skin
            extensionsPage.ExtensionPackageSelectList.Select("Skin");
            System.Threading.Thread.Sleep(500);
            extensionsPage.GetExtensionUninstallButton(SkinName).Click();
            System.Threading.Thread.Sleep(2000);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                extensionsPage.UninstallPackageLink.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            ieInstance.WaitForComplete();

            //Uninstall the Container
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
            extensionsPage.ExtensionPackageSelectList.Select("Container");
            System.Threading.Thread.Sleep(500);
            extensionsPage.GetExtensionUninstallButton(SkinName).Click();
            System.Threading.Thread.Sleep(2000);
            dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                extensionsPage.UninstallPackageLink.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            ieInstance.WaitForComplete();
            SkinInstalled = false;

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/Skins.aspx");
            AdminSkinPage skinPage = new AdminSkinPage(homePage);
            skinPage.ContainerSelectList.Select(SkinName);
            skinPage.DeleteSkinPackageLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            Assert.IsTrue(skinPage.SkinSelectList.Option(SkinName).Exists);
            Assert.IsFalse(skinPage.ContainerSelectList.Option(SkinName).Exists);
            Assert.IsFalse(Directory.Exists(PhysicalPath + "/Portals/_default/Containers/" + SkinName));
            Assert.IsTrue(Directory.Exists(PhysicalPath + "/Portals/_default/Skins/" + SkinName));
            Directory.Delete(PhysicalPath + "/Portals/_default/Skins/" + SkinName, true);
        }


        #endregion
    }
}